Skip to content

feat(web): store draft and stashed attachments in IndexedDB - #1094

Merged
badcuban merged 2 commits into
mainfrom
fix/draft-image-save-error
Nov 24, 2026
Merged

badcuban merged 2 commits into
mainfrom
fix/draft-image-save-error

Conversation

@badcuban

Copy link
Copy Markdown
Collaborator

Draft attachments and stashed prompts previously saved raw files as base64 data URLs inside localStorage, which shares a ~5 MB per-origin quota across the app and enforced a 3.5 MB draft cutoff and 2.7 MB stash budget. Large screenshots (such as macOS Retina PNGs) and device recordings hit those limits and showed a warning saying the attachment may be lost "on navigation".

This change moves both composer draft attachments and prompt stash attachments to binary Blob storage in IndexedDB (threadlines-draft-attachments) while keeping only lightweight metadata in localStorage:

  • Shared IndexedDB blob store. Stores raw Blob bytes under separate draft:<id> and stash:<entryId>:<id> keys with a serialized mutation queue, explicit deletion on remove/clear/send/restore/delete/eviction, and a startup orphan sweep with a 10-minute grace period.
  • Hydration and transfer safety. Hydrates draft attachments asynchronously on reload without dirtying cross-tab write tracking, waits for pending hydration or stash restore before sending or stashing, keeps metadata with a removable warning tile on transient read errors, preserves edits made during stashing, and writes destination drafts before consuming stashed entries.
  • Backwards-compatible migration. Loads existing inline dataUrl drafts and stashed prompts, migrates their bytes into IndexedDB on startup without dropping working inline copies if IndexedDB fails, and retires legacy t3code:composer-drafts:v1 keys once compacted.
  • Limits and copy cleanup. Removes the 3.5 MB draft cap, the 2.7 MB stash budget, and lossy stash image recompression (stashImageCompression.ts). Checks saved attachment IDs structurally per thread instead of strict-decoding unrelated drafts, merges prompt stash writes across tabs, and updates the unsaved attachment tooltip to say "may be lost on reload."

Verification

  • vp fmt
  • vp lint
  • vp run typecheck
  • vp run --cache '@threadlines/web#test' composerDraftStore promptStashStore (107 tests)
  • vp run --cache '@threadlines/web#test:browser' (118 files, 1,222 tests)

Draft attachments and stashed prompts previously saved raw files as base64 data URLs inside localStorage, which shares a ~5 MB per-origin quota across the app and enforced a 3.5 MB draft cutoff and 2.7 MB stash budget. Large screenshots and device recordings hit those limits and showed a warning saying the attachment may be lost "on navigation".

Move both composer draft attachments and prompt stash attachments to binary Blob storage in IndexedDB while keeping only lightweight metadata in localStorage:

- Store draft and stash blobs under separate owner keys with a serialized mutation queue, explicit cleanup on remove, clear, send, restore, delete, and eviction, plus a startup orphan sweep with a 10-minute grace period.
- Hydrate IndexedDB-backed draft attachments asynchronously on reload without dirtying cross-tab write tracking, wait for pending hydration or stash restore before sending or stashing, preserve metadata with a removable tile on transient read errors, and count hydrating files against the 8-attachment limit.
- Migrate existing inline dataUrl drafts and stashed prompts into IndexedDB on startup, keep working inline copies intact if IndexedDB fails, and retire legacy t3code:composer-drafts:v1 keys once compacted.
- Remove the 3.5 MB draft cutoff, the 2.7 MB stash budget, and lossy stash image recompression.
- Verify draft attachment persistence structurally for the active thread instead of strict-decoding unrelated drafts, merge prompt stash writes against the latest stored queue across tabs, and update the unsaved attachment tooltip to say "may be lost on reload."
@vercel

vercel Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated
threadlines Skipped Skipped Nov 24, 2026 9:46pm UTC

Request Review

Move IndexedDB draft hydration, legacy dataUrl migration, orphan cleanup, and async stash/restore orchestration behind dynamic imports so startup bundles stay within the web gzip budget.
@badcuban
badcuban added this pull request to the merge queue Nov 24, 2026
Merged via the queue into main with commit f33cafc Nov 24, 2026
25 checks passed
@badcuban
badcuban deleted the fix/draft-image-save-error branch November 24, 2026 21:59

This branch was previously deployed

1 inactive deployment
Preview — 84b414b5 Deployed Nov 24, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant